package jman.teemwork12;

public class Business extends User{
	private Shop shop=new Shop();
	public Business(){
	}
	public Business(Shop shop){
		this.shop=shop;
	}
	public Business(String name, String password) {
		setUserName(name);
		setPassword(password);
	}
	public Shop getShop() {
		return shop;
	}
	public void setShop(Shop shop) {
		this.shop = shop;
	}
	public void getBusiness(String shopName){
		this.shop.setShopname(shopName);
	}
	//添加商品
	public void addCommodity(Commodity commodity) throws Exception{
		if(this.shop.getHashMap()!=null&&this.shop.getHashMap().containsKey(commodity.getCommodityName())){
			this.shop.getHashMap().get(commodity.getCommodityName()).setNumber(this.shop.getHashMap().get(commodity.getCommodityName()).getNumber()+commodity.getNumber());
		}else{
			this.shop.getHashMap().put(commodity.getCommodityName(), commodity);
		}
	}
	//修改商品的名字
	public void updateCommodityName(Commodity commodity,String newCommodityName) throws Exception{
		if(this.shop.getHashMap().containsKey(commodity.getCommodityName())){
			this.shop.getHashMap().get(commodity.getCommodityName()).setCommodityName(newCommodityName);
		}
	}
	//修改商品的数量
	public void updateCommodityNumber(Commodity commodity,int newnumber) throws Exception{
		if(this.shop.getHashMap().containsKey(commodity.getCommodityName())){
			this.shop.getHashMap().get(commodity.getCommodityName()).setNumber(newnumber);;
		}
	}
	//修改商品的价格
	public void updateCommodityPrice(Commodity commodity,double newprice) throws Exception{
		if(this.shop.getHashMap().containsKey(commodity.getCommodityName())){
			this.shop.getHashMap().get(commodity.getCommodityName()).setPrice(newprice);;
		}
	}
}
